/**
 * Created by Administrator on 2016-08-18.
 */
$(function () {
    var self = {
        init: function () {
            self.login();
            self.events();
        },
        events:function () {
            //搜索模块开始
           $(document).on('click', '.J_SearchBtn', function (e) {
               var queryVal = $(".J_SearchVal").val();
               if(queryVal !==''){
                   location.href = WWW_URL + '/query2/index/0-1-' + queryVal + '-0-1.html';
               }
            });

            $(document).on('keyup', '.J_SearchVal', function (e) {
                if (e.keyCode == 13) {
                    $(".J_SearchBtn").trigger('click');
                }
            });

            //wap端搜索模块
            $(document).on('click','.searchBtn',function(){
                var querywordVal = $("#querywords").val(),
                    WAP_WWW_URl = 'http://m.cjwsc.com';
                if(querywordVal !== ''){
                    location.href = WAP_WWW_URl + '/lists?from=opensearch&queryVal=' + querywordVal;
                }
            });

            //搜索模块结束
        },
        login: function () {
            var WWW_URL = 'http://www.cjwsc.com/';
            var url = WWW_URL + 'ztApi';
            $.ajax({
                type: "POST",
                url: url,
                dataType: "jsonp",
                jsonp: "jsonpcallback",
                timeout: 5000,
                success: function (ret) {
                    //var ret = eval("("+data+")");
                    if (ret.error === false) {
                        var userCenter = WWW_URL + 'member/member';
                        $('#loginLink').removeClass('red-da3').html(ret.msg.username);
                        $('#user_id').val(ret.msg.userId);
                        $('#loginLink').attr('href', userCenter);
                        $('#loginOut').removeClass('display-none');
                    } else {
                        $('#loginOut').addClass('display-none');
                        return false;
                    }
                },
                error: function () {
                    console.log("error")
                }
            });
        }
    };
    self.init();
});


